package ru.papergames.web.blines.battle.network.clientpackets;

import ru.common.network.clientcore.SendablePacket;
import ru.papergames.web.blines.battle.network.ClientWebServer;

import java.util.logging.Logger;

/**
 * @author: atroshanin
 * Date: 18.04.2010
 * Time: 14:16:34
 */
public abstract class WebServerClientPacket extends SendablePacket<ClientWebServer> implements WebServerClientPacketTypes {
    private static final Logger _log = Logger.getLogger(WebServerClientPacket.class.getName());

    protected boolean _invisible = false;

    /**
     * @return True if packet originated from invisible character.
     */
    public boolean isInvisible() {
        return _invisible;
    }

    /**
     * Set "invisible" boolean flag in the packet.
     * Packets from invisible characters will not be broadcasted to players.
     *
     * @param b
     */
    public void setInvisible(boolean b) {
        _invisible = b;
    }

    /**
     * @see SendablePacket#write()
     */
    @Override
    protected void write() {
        try {
            writePacketId();
            //_log.info(this.getType());
            writePacketData();
        }
        catch (Exception e) {
            //_log.severe("Client: " + getClient().toString() + " - Failed writing: " + getType() + " - L2J Server Version: " + Config.SERVER_VERSION + " - DP Revision: " + Config.DATAPACK_VERSION);
            e.printStackTrace();
        }
    }

    public void runImpl() {

    }

    protected abstract void writePacketId();

    protected abstract void writePacketData();

    /**
     * @return A String with this packet name for debuging purposes
     */
    public abstract String getType();
}
